function SceneScene8(options) {
	this.options = options;
	

}

function populateScene(obj) {
    
}

function populatePanels(obj,count,values) {// obj-oryginał ramki, count-liczba kopii, values[][]-tabela tabel z wartościami - docelowo tabela JSONÓW
    var arr = [];
    for(var i =0;i<count;i++) {
        var mat = copyElement(obj);
        setPanelValues(mat,values[i]);
        arr[i] = mat;
    }
    return arr;
}


function setPanelValues(obj,arr) {
    for(var i in obj.children) {
        //alert(i);
        if(obj.children[i].id != 'image') {
            obj.children[i].innerText = arr[i];
        }
    }
}

function arrangeTable(panels,x,y,w,h,col,row) {
    
    var table = document.createElement("div");
    table.style.left = x;
    table.style.top = y;
    table.style.width = w;
    table.style.height = h;
    table.style.position = "absolute";
    
	table.id = "response";
	
    for(var i=0;i<panels.length;i++) {
        var c = i%col;
        var r = Math.floor(i/col);
        
		resizeBlock(panels[i],Math.floor(w/col)-5,Math.floor(h/row)-4,false);
        // alert('?!?!?!?!?!?!?!?!?!?!?!');
		moveBlock(panels[i],Math.ceil(c*(w/col))+2,Math.ceil(r*(h/row))+2,false);
        panels[i].style.display = "block";
        table.appendChild(panels[i]);
    }
    
    return table;
}


SceneScene8.prototype.updateList = function (GData) {
	var container = document.getElementById("SceneScene8");
	
	GData.suggestionList.push("dummy");
	GData.suggestionList.push("dummy");
	GData.suggestionList.push("dummy");
	GData.suggestionList.push("dummy");
	GData.suggestionList.push("dummy");
	GData.suggestionList.push("dummy");
	GData.suggestionList.push("dummy");
	// GData.suggestionList.push("dummy");
	
	var siz = GData.suggestionList.length;
	var col = Math.ceil(siz/5);
	var row = Math.ceil(siz/col);
	var wid=600, hei=500;
	
	var vals = [];
    for(var i=0;i<siz;i++) {
        vals[i] = [i+' Dummy programm',i,,'32894','667min','25:87'];
		if(GData.suggestionList[i])
			vals[i][0] = GData.suggestionList[i];
    }
    
	
	this.prot.style.border = "solid black 2px";
	resizeBlock(this.prot,wid/col,hei/row,false);
	
    var panels = populatePanels(this.prot,siz,vals);
    
	// if(row < 4) row = 4;
	
	var olddiv = document.getElementById('response');
	if (olddiv) {
		container.removeChild(olddiv);
		olddiv = document.getElementById('response');
	} 
	
	var sc1 = $.sfScene.get('Scene1');
	container.appendChild(arrangeTable(panels,340,20,wid,hei,col,row));
	if(sc1.container == GlobalContainer[1])
		var swap = true;
	
	GlobalContainer[1] = new UserControlGroup('response UCG',col,row);
	
	var cont = GlobalContainer[1];
    
    for(var i=0;i<siz;i++) {
        var c = i%col;
        var r = Math.floor(i/col);
        cont.registerObject(new PanelUserControl('name',panels[i]),r,c);
    }
	
	cont.activate(panels[0]);
	if(swap)
		sc1.container = cont;
	
	// printObject(panels[0]);
	alert('panel_cont '+panels[0].clientWidth+' '+panels[0].clientHeight);
	for(var i=0;i<panels[0].children.length;i++) {
		// printObject(panels[0].children[i]);
		alert(panels[0].children[i].id+' '+panels[0].children[i].clientWidth+' '+panels[0].children[i].clientHeight);
	}
}



SceneScene8.prototype.initialize = function () {
	alert("SceneScene8.initialize()");
	this.prot = document.getElementById("SceneScene7");
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here 
	// scene HTML and CSS will be loaded before this function is called
	
    $('#but_less').sfButton({text:'<', width:'40px'});
	$('#act_val').sfLabel({text:'100', width:'40px'});
	$('#but_more').sfButton({text:'>', width:'40px'});
	$('#prop_lab').sfLabel({text:'Brutalnosc', width:'100px'});
	$('#larg_image').sfImage({src:'images/panel.background.jpg'});
	$('#larg_dir').sfLabel({text:'Director:', width:'85px'});
	$('#larg_dir_name').sfLabel({text:'director_name', width:'110px'});
	$('#larg_act').sfLabel({text:'Actors:', width:'95px'});
	$('#larg_atc_names').sfLabel({text:'sadggggggggggggggggggggggggggg', width:'100px'});
	$('#larg_year').sfLabel({text:'Year', width:'130px'});
	$('#larg_year_val').sfLabel({text:'label', width:'115px'});
	$('#larg_short_desc').sfLabel({text:'short_desctirption', width:'210px'});
	$('#larg_comments').sfLabel({text:'other_comments', width:'130px'});
	$('#larg_fb').sfLabel({text:'fb_info', width:'130px'});
    
    fixButton('but_less');
	fixButton('but_more');
	
    
    /* sugg */
    
    // alert('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!suggggg!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
    ServerProxy.getSuggestions(new Profile());
    // printObject(GData.suggestions);
    // alert('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!suggggg!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
    
    
    
    // var arr = ['Czas honoru',5,,'2007','110min','16:50'];
    // setPanelValues(prot,arr);
}




SceneScene8.prototype.handleShow = function () {
	// ServerProxy.getSuggestions(new Profile());
	alert("SceneScene8.handleShow()");
	// this function will be called when the scene manager show this scene 
}

SceneScene8.prototype.handleHide = function () {
	alert("SceneScene8.handleHide()");
	// this function will be called when the scene manager hide this scene  
}

SceneScene8.prototype.handleFocus = function () {
	alert("SceneScene8.handleFocus()");
	// this function will be called when the scene manager focus this scene
}

SceneScene8.prototype.handleBlur = function () {
	alert("SceneScene8.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
}

SceneScene8.prototype.handleKeyDown = function (keyCode) {
	alert("SceneScene8.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
	switch (keyCode) {
		case $.sfKey.LEFT:
			break;
		case $.sfKey.RIGHT:
			break;
		case $.sfKey.UP:
			break;
		case $.sfKey.DOWN:
			break;

		case $.sfKey.ENTER:
			break;
	}
}
